home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Snippets / FindIcon / Find_icon.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-26  |  2.4 KB  |  101 lines  |  [TEXT/KAHL]

  1. #include "Find_icon.h"
  2. #include <exceptions.h>
  3. #include <Finder.h>
  4. #include "Get_custom_folder_icon.h"
  5. #include "Get_normal_folder_icon.h"
  6. #include "Get_volume_icon.h"
  7. #include "Get_custom_file_icon.h"
  8. #include "Get_normal_file_icon.h"
  9. #include "Is_vol_ejected.h"
  10.  
  11. /*    ------------------------------------------------------------------
  12.     Find_icon        Given a file specification for a file, folder, or
  13.                     volume, create an appropriate icon suite
  14.                     and find its label color.
  15.     ------------------------------------------------------------------
  16. */
  17. pascal OSErr Find_icon(
  18. /* --> */    FSSpec    *thing,
  19. /* --> */    IconSelectorValue    icon_selector,
  20. /* --> */    ConstStr31Param        icon_file_name,
  21. /* <-- */    Handle    *the_suite,
  22. /* <-- */    short    *label_color
  23. )
  24. {
  25.     CInfoPBRec        cpb;
  26.     OSErr            err;
  27.     
  28.     *the_suite = NULL;
  29.     *label_color = 0;
  30.     
  31.     forbid_action( Is_vol_ejected( thing->vRefNum ), ejected,
  32.         err = volOffLinErr );
  33.     
  34.     cpb.hFileInfo.ioVRefNum = thing->vRefNum;
  35.     cpb.hFileInfo.ioDirID = thing->parID;
  36.     cpb.hFileInfo.ioNamePtr = thing->name;
  37.     cpb.hFileInfo.ioFDirIndex = 0;
  38.     err = PBGetCatInfoSync( &cpb );
  39.     forbid( err, PBGetCatInfoSync );
  40.     
  41.     /*
  42.         Shifted this way, the color is ready to be used as an
  43.         icon transformation.
  44.     */
  45.     *label_color = (cpb.hFileInfo.ioFlFndrInfo.fdFlags & kColor) << 7;
  46.     
  47.     if ( (cpb.hFileInfo.ioFlAttrib & ioDirMask) == 0 )    // file
  48.     {
  49.         if (cpb.hFileInfo.ioFlFndrInfo.fdFlags & kHasCustomIcon)
  50.         {
  51.             err = Get_custom_file_icon( thing,
  52.                 icon_selector, the_suite );
  53.         }
  54.         else    // no custom icon
  55.         {
  56.             err = Get_normal_file_icon( &cpb,
  57.                 icon_selector, the_suite );
  58.         }
  59.     }
  60.     else    // directory
  61.     {
  62.         if (cpb.hFileInfo.ioFlFndrInfo.fdFlags & kHasCustomIcon)
  63.         {
  64.             err = Get_custom_folder_icon( thing->vRefNum,
  65.                 cpb.hFileInfo.ioDirID, icon_selector, icon_file_name,
  66.                 the_suite );
  67.         }
  68.         else    // no custom icon
  69.         {
  70.             if (cpb.hFileInfo.ioDirID == fsRtDirID)    // a volume
  71.             {
  72.                 err = Get_volume_icon( thing->vRefNum,
  73.                     icon_selector, the_suite );
  74.             }
  75.             else    // a folder
  76.             {
  77.                 err = Get_normal_folder_icon( &cpb,
  78.                     icon_selector, the_suite );
  79.             }
  80.         }
  81.     }
  82.     goto getout;
  83.     // ----------- end of normal case --------------
  84.  
  85. ejected:
  86. PBGetCatInfoSync:    // ------- error handler ---------
  87.     if (thing->parID == fsRtParID)    // a volume
  88.     {
  89.         if (err == volOffLinErr)
  90.         {
  91.             *label_color = ttOffline;
  92.         }
  93.         err = Get_volume_icon( thing->vRefNum,
  94.                     icon_selector, the_suite );
  95.     }
  96.  
  97.  
  98. getout:
  99.     return err;
  100. }
  101.